package com.acme.bankapp.service.bank;

/**
 * Class which represents Account functional
 * including overdraft
 * 
 * @author render1980
 *
 */
public class CheckingAccount extends AbstractAccount{
	private double overdraft;
	
	public CheckingAccount(final double amount, final double overdraft) {
		super(amount);
		this.overdraft = overdraft;
		this.balance = amount;
	}
	
	public void withdraw(double x) {
		if(x <= this.balance) {
			this.balance -= x;
			return;
		}
		
		if(x > this.balance) {
			if(x > this.maximumAmountToWithdraw()) {
				System.out.println("Not enough money!");
				return;
			}
			this.overdraft -= (x -= this.balance);
			this.balance = 0;
		}
	}
	
	public double maximumAmountToWithdraw() {
		return this.balance + this.overdraft;
	}
}